'use strict';
ymb.controller('myinformation', ['$scope', '$state', 'WecHat', 'WeChat', '$http', '$okgo', '$ionicLoading', '$$display', '$PlPup', '$go', '$ionicViewSwitcher', '$ionicPopup',
function($scope, $state, WecHat, WeChat, $http, $okgo, $ionicLoading, $$display, $PlPup, $go, $ionicViewSwitcher, $ionicPopup) {
    WeChat.WxData();
    WecHat.inData('我的');
    $ionicLoading.show({
        content: 'Loading',
        animation: 'fade-in',
        showBackdrop: true,
        maxWidth: 200,
        showDelay: 0
    });
    $http.post(url + '/user/selecttotalmoney', {}).success(function(data) {
        $ionicLoading.hide();
        $scope.balance = data.balance;
        $scope.account_money = data.account_money;
        $scope.total_money = data.total_money;
        $scope.nickname = data.nickname;
        $scope.img_wp = data.photo
    });
    $scope.display = 2;
    $$display.$display($scope, $http);
    $scope.$on('$ionicView.beforeEnter',
    function() {
        var t = document.title;
        $http.post(url + '/user/selecttotalmoney', {}).success(function(data) {
            $scope.balance = data.balance;
            $scope.expenditureMoney = data.expenditureMoney;
            $scope.total_money = data.total_money;
            $scope.nickname = data.nickname;
            $scope.img_wp = data.photo
        });
        $$display.$display($scope, $http);
        if (typeof t == "string" && typeof t != "null" && typeof t != "我的") {
            document.title = "我的"
        }
    });
    $scope.buckle = function() {
        $http.post(url + '/user/ifidentification', {}).success(function(data) {
            if (data.code === '00') {
                $okgo.$$go('wallet');
                return
            }
            if (data.code !== '00') {
                $okgo.$$go('real');
                return
            }
        })
    };
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    $scope.Sign_out_up = function() {
        var Sign_out = $ionicPopup.confirm({
            title: '提示',
            template: '您真的要退出登录吗',
            cancelText: '考虑一下',
            okText: '狠心退出'
        });
        Sign_out.then(function(res) {
            if (res) {
                $http.post(url + '/user/userexit', {
                    token: $scope.token
                }).success(function(data) {
                    if (data.code === '00') {
                        $go.$goUp('tabs.homepage');
                        return
                    }
                    if (data.code !== '00') {
                        $scope.token = "";
                        $http.get(url + "/user/getToken").success(function(data) {
                            $scope.token = data.data
                        });
                        $PlPup.$model(data.data);
                        return
                    }
                });
                return
            }
        })
    };
    $scope.nodelname = "我要开店";
    $scope.mycode = 2;
    /*
    $http.get(url + '/shop/ifopenshop').success(function(data) {
        if (data.data == "true") {
            $scope.nodelname = "我的店铺";
            $scope.mycode = 1;
            return
        }
        if (data.data == "false") {
            $scope.nodelname = "我要开店";
            $scope.mycode = 2;
            return
        }
    });
    */
    $scope.playdian = function() {
        $http.post(url + '/user/iflogin', {}).success(function(data) {
            if (data.code === '08') {
                // $ionicPopup.alert({
                //     title: '提示',
                //     template: '小主，产品正在升级中，升级完成会通知你的哦！',
                //     okText: "知道啦"
                // });
                $state.go("shop");
                $ionicViewSwitcher.nextDirection("forward");
                if ($scope.mycode == 2) {
                    $state.go("shop");
                    $ionicViewSwitcher.nextDirection("forward");
                    return
                }
                if ($scope.mycode == 1) {
                    $state.go("shop");
                    $ionicViewSwitcher.nextDirection("forward");
                    return
                }
                return true
            }
            if (data.code !== '08') {
                $state.go("sign");
                $ionicViewSwitcher.nextDirection("forward");
                return true
            }
        })
    }
}]);
ymb.controller('messages', ['$scope', 'WecHat', 'WeChat', '$http', '$myfor', '$okgo',
function($scope, WecHat, WeChat, $http, $myfor, $okgo) {
    WeChat.WxData();
    WecHat.inData('我的信息');
    $myfor.$my_fortion($http, $scope);
    $scope.buckle_messages = function() {
        $http.post(url + '/user/ifidentification', {}).success(function(data) {
            if (data.code === '00') {
                return
            }
            if (data.code !== '00') {
                $okgo.$$go('real');
                return
            }
        })
    }
}]);
ymb.controller('names', ['$scope', 'WeChat', 'WecHat', '$http', '$PlPup',
function($scope, WeChat, WecHat, $http, $PlPup) {
    WeChat.WxData();
    WecHat.inData('修改名称');
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    $scope.namesOuEr = "";
    $scope.namesto = function() {
        if ($scope.namesOuEr.length === 0) {
            $PlPup.$model('请输入您想要修改的名称');
            return
        }
        $http.post(url + '/user/updatenickname', {
            nickname: $scope.namesOuEr,
            token: $scope.token
        }).success(function(data) {
            if (data.code === '33') {
                window.history.back();
                return
            }
            if (data.code !== '33') {
                $scope.token = "";
                $http.get(url + "/user/getToken").success(function(data) {
                    $scope.token = data.data
                });
                $PlPup.$model(data.data);
                return
            }
        })
    }
}]);
ymb.controller('gender', ['$scope', 'WeChat', 'WecHat', '$http', '$PlPup',
function($scope, WeChat, WecHat, $http, $PlPup) {
    WeChat.WxData();
    WecHat.inData('我的信息');
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    $scope.sex = '男';
    $scope.ns_img = 'myimg/cmoder10.png';
    $scope.nv_img = 'myimg/cmoder11.png';
    $scope.ok_gender = function(e) {
        if (e === 1) {
            $scope.ns_img = 'myimg/cmoder10.png';
            $scope.nv_img = 'myimg/cmoder11.png';
            $scope.sex = '男'
        } else {
            $scope.ns_img = 'myimg/cmoder11.png';
            $scope.nv_img = 'myimg/cmoder10.png';
            $scope.sex = '女'
        }
    };
    $scope.ok_sex = function() {
        $http.post(url + '/user/updatesex', {
            sex: $scope.sex,
            token: $scope.token
        }).success(function(data) {
            if (data.code === '33') {
                window.history.back();
                return
            }
            if (data.code !== '33') {
                $scope.token = "";
                $http.get(url + "/user/getToken").success(function(data) {
                    $scope.token = data.data
                });
                $PlPup.$model(data.data);
                return
            }
        })
    }
}]);
ymb.controller('accman', ['$scope', 'WeChat', 'WecHat', '$http', '$myfor', '$go', '$PlPup', '$ionicPopup',
function($scope, WeChat, WecHat, $http, $myfor, $go, $PlPup, $ionicPopup) {
    WeChat.WxData();
    WecHat.inData('账号管理');
    $myfor.$my_fortion($http, $scope);
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    $scope.Sign_out_up = function() {
        var Sign_out = $ionicPopup.confirm({
            title: '提示',
            template: '您真的要退出登录吗',
            cancelText: '考虑一下',
            okText: '狠心退出'
        });
        Sign_out.then(function(res) {
            if (res) {
                $http.post(url + '/user/userexit', {
                    token: $scope.token
                }).success(function(data) {
                    if (data.code === '00') {
                        $go.$goUp('tabs.homepage');
                        return
                    }
                    if (data.code !== '00') {
                        $scope.token = "";
                        $http.get(url + "/user/getToken").success(function(data) {
                            $scope.token = data.data
                        });
                        $PlPup.$model(data.data);
                        return
                    }
                });
                return
            }
        })
    }
}]);
ymb.controller('phone', ['$scope', 'WeChat', 'WecHat', '$interval', '$http', '$PlPup',
function($scope, WeChat, WecHat, $interval, $http, $PlPup) {
    WeChat.WxData();
    WecHat.inData('修改手机号码');
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    $scope.disabledS = false;
    $scope.Obtain = '发送验证码';
    $scope.nodeBa = 1;
    $scope.hash = '';
    $scope.tamp = '';
    $scope.newPhone = '';
    $scope.newcation = '';
    $scope.newidcard = '';
    $scope.newphone = function() {
        if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test($scope.newPhone)) {
            $PlPup.$model('请输入您正确的手机号码');
            return
        }
        $scope.disabledS = true;
        $scope.TimeS = 60;
        $scope.Obtain = 60 + 'S';
        $scope.nodeBa = 2;
        $scope.timerI = $interval(function() {
            $scope.TimeS--;
            $scope.Obtain = $scope.TimeS + 'S';
            if ($scope.TimeS === 0) {
                $scope.nodeBa = 1;
                $scope.Obtain = '获取验证码';
                $interval.cancel($scope.timerI);
                $scope.disabledS = false;
                return
            }
        },
        1000);
        $http.post(url + '/user/sendSMS', {
            phoneNumber: $scope.newPhone,
            smstype: "cp"
        }).success(function(data) {
            $scope.hash = data.hash;
            $scope.tamp = data.tamp
        })
    };
    $scope.verify = function() {
        if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test($scope.newPhone)) {
            $PlPup.$model('请输入您正确的手机号码');
            return
        }
        if ($scope.newcation.length !== 4) {
            $PlPup.$model('请输入正确的4位验证码');
            return
        }
        if ($scope.hash.length === 0 || $scope.hash === null) {
            $PlPup.$model('手机验证码失效，请重新输入');
            return
        }
        var phoneData = {
            phone: $scope.newPhone,
            msgNum: $scope.newcation,
            hash: $scope.hash,
            tamp: $scope.tamp,
            token: $scope.token
        };
        $http.post(url + '/user/updatephone', phoneData).success(function(data) {
            if (data.code === '00') {
                window.history.back();
                return
            }
            if (data.code !== '00') {
                $scope.token = "";
                $http.get(url + "/user/getToken").success(function(data) {
                    $scope.token = data.data
                });
                $PlPup.$model(data.data);
                return
            }
        })
    }
}]);
ymb.controller('reset', ['$scope', '$state', '$ionicViewSwitcher', 'WeChat', 'WecHat', '$http', '$PlPup', '$eye','$ionicPopup',
function($scope, $state, $ionicViewSwitcher, WeChat, WecHat, $http, $PlPup, $eye,$ionicPopup) {
    WeChat.WxData();
    WecHat.inData('重置密码');
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    $eye.$my_eye($scope);
    $scope.usedpwd = '';
    $scope.newpwd = '';
    $scope.oknewpwd = '';
    $scope.reset_ok = function() {
        if ($scope.newpwd.length < 6 || $scope.newpwd.length > 16 || /^[\u4E00-\u9FA5]{1,5}$/.test($scope.newpwd)) {
            $PlPup.$model('请设置6-16位数字字母组合密码');
            return
        }
        if ($scope.newpwd !== $scope.oknewpwd) {
            $PlPup.$model('新密码和确认密码不同，请重新输入');
            return
        }
        var resetData = {
            usedpwd: pwdencode($scope.usedpwd),
            newpwd: pwdencode($scope.newpwd),
            rpwd: pwdencode($scope.oknewpwd),
            token: $scope.token
        };
        $http.post(url + '/user/updatepwd', resetData).success(function(data) {
            if (data.code === '28') {
                var confirmPopup = $ionicPopup.alert({
                    title: '提示',
                    template: '恭喜您重置密码成功',
                    okText: '确定'
                });
                confirmPopup.then(function (res) {
                    window.history.back();
                });
                return
            }
            if (data.code !== '28') {
                $scope.token = "";
                $http.get(url + "/user/getToken").success(function(data) {
                    $scope.token = data.data
                });
                $PlPup.$model(data.data);
                return
            }
        })
    }
}]);

// 修改交易密码
ymb.controller('resettrade', ['$scope', '$state', '$ionicViewSwitcher', 'WeChat', 'WecHat', '$http', '$PlPup', '$eye','$ionicPopup',
    function($scope, $state, $ionicViewSwitcher, WeChat, WecHat, $http, $PlPup, $eye,$ionicPopup) {
        WeChat.WxData();
        WecHat.inData('修改交易密码');
        $scope.token = "";
        $http.get(url + "/user/getToken").success(function(data) {
            $scope.token = data.data
        });
        $eye.$my_eye($scope);
        $scope.usedpwd = '';
        $scope.newpwd = '';
        $scope.oknewpwd = '';
        $scope.updatetradepwd_up = function() {
            if ($scope.newpwd.length > 6|| !/^[0-9]{6}$/.test($scope.newpwd)) {
                $PlPup.$model('请设置6为纯数字密码');
                return
            }
            if ($scope.newpwd !== $scope.oknewpwd) {
                $PlPup.$model('新密码和确认密码不同，请重新输入');
                return
            }
            // pwdencode($scope.usedpwd)
            var resetData = {
                usedpwd: $scope.usedpwd,
                newpwd: $scope.newpwd,
                rpwd: $scope.oknewpwd,
                token: $scope.token
            };
            $http.post(url + '/user/updatePaypwd', resetData).success(function(data) {
                if (data.code === '28') {
                    var confirmPopup = $ionicPopup.alert({
                        title: '提示',
                        template: '恭喜您重置交易密码成功',
                        okText: '确定'
                    });
                    confirmPopup.then(function (res) {
                        window.sessionStorage.setItem("paypwd",$scope.newpwd);
                        window.history.back();
                    });
                    return
                }
                if (data.code !== '28') {
                    $scope.token = "";
                    $http.get(url + "/user/getToken").success(function(data) {
                        $scope.token = data.data
                    });
                    $PlPup.$model(data.data);
                    return
                }
            })
        }
    }]);


ymb.controller('sign', ['$scope', '$http','$state', 'WeChat', 'WecHat', '$PlPup', '$eye', '$ionicViewSwitcher',
function($scope, $http,$state, WeChat, WecHat, $PlPup, $eye, $ionicViewSwitcher) {
    WeChat.WxData();
    WecHat.inData('登录');
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    $eye.$my_eye($scope);
    $scope.signPhone = '';
    $scope.signPwd = '';
    $scope.signOk = function() {
        if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test($scope.signPhone)) {
            $PlPup.$model('请输入您正确的手机号码');
            return
        }
        if ($scope.signPwd.length < 6 || $scope.signPwd.length > 16 || /^[\u4E00-\u9FA5]{1,5}$/.test($scope.signPwd)) {
            $PlPup.$model('请设置6-16位数字字母组合密码');
            return
        }
        var signData = {
            phone: $scope.signPhone,
            loginpwd: pwdencode($scope.signPwd),
            token: $scope.token
        };
        $http.post(url + '/user/login', signData).success(function(data) {
            if (data.code === '00') {
                // $ionicViewSwitcher.nextDirection('back');
                // window.history.go( - 1);
               $state.go("tabs.homepage");
                return
            }
            if (data.code !== '00') {
                $scope.token = "";
                $http.get(url + "/user/getToken").success(function(data) {
                    $scope.token = data.data
                });
                $PlPup.$model(data.data);
                return
            }
            $PlPup.$model('请关闭微信浏览器，重新进入')
        })
    }
}]);

// 验证码登录
ymb.controller('loginbycode', ['$scope', '$http','$state', 'WeChat', 'WecHat', '$PlPup', '$eye', '$ionicViewSwitcher','$interval',
    function($scope, $http,$state, WeChat, WecHat, $PlPup, $eye, $ionicViewSwitcher,$interval) {
        WeChat.WxData();
        WecHat.inData('登录');
        $scope.token = "";
        $http.get(url + "/user/getToken").success(function(data) {
            $scope.token = data.data
        });
        $eye.$my_eye($scope);
        $scope.signPhone = '';
        $scope.cation = '';
        $scope.disabledS = false;
        $scope.Obtain = '发送验证码';
        $scope.nodeBa = 1;
        $scope.hash = '';
        $scope.tamp = '';
        $scope.newPhone = '';
        $scope.newcation = '';
        $scope.newidcard = '';
        $scope.Send_out = function() {
            if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test($scope.signPhone)) {
                $PlPup.$model('请输入您正确的手机号码');
                return
            }
            $scope.disabledS = true;
            $scope.TimeS = 60;
            $scope.Obtain = 60 + 'S';
            $scope.nodeBa = 2;
            $scope.timerI = $interval(function() {
                    $scope.TimeS--;
                    $scope.Obtain = $scope.TimeS + 'S';
                    if ($scope.TimeS === 0) {
                        $scope.nodeBa = 1;
                        $scope.Obtain = '获取验证码';
                        $interval.cancel($scope.timerI);
                        $scope.disabledS = false;
                        return
                    }
                },
                1000);
            $http.post(url + '/user/sendSMS', {
                phoneNumber: $scope.signPhone,
                smstype: "cp"
            }).success(function(data) {
                $scope.hash = data.hash;
                $scope.tamp = data.tamp
            })
        };
        $scope.signOk = function() {
            if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test($scope.signPhone)) {
                $PlPup.$model('请输入您正确的手机号码');
                return
            }
            if ($scope.cation.length !== 4) {
                $PlPup.$model('请输入您正确的验证码');
                return
            }
            if ($scope.hash.length === 0) {
                $PlPup.$model('请先发送短信');
                return
            }
            var signData = {
                phone: $scope.signPhone,
                token: $scope.token,
                tamp: $scope.tamp,
                hash: $scope.hash,
                msgNum: $scope.cation
            };
            $http.post(url + '/user/loginBySms', signData).success(function(data) {
                if (data.code == '00') {
                    $state.go("tabs.homepage");
                    return
                }
                if (data.code !== '00') {
                    $scope.token = "";
                    $http.get(url + "/user/getToken").success(function(data) {
                        $scope.token = data.data
                    });
                    $PlPup.$model(data.data);
                    return
                }
                $PlPup.$model('请关闭微信浏览器，重新进入')
            })
        }
    }]);
ymb.factory('$sames',
function() {
    var $sames_up = {};
    $sames_up.$$same_Up = function($scope, $http, $interval, $go, $PlPup, urls, verification,$ionicPopup,$ionicModal,$state,$ionicLoading) {
        $scope.token = "";
        $http.get(url + "/user/getToken").success(function(data) {
            $scope.token = data.data
        });
        $scope.disabledS = false;
        $scope.Obtain = '获取验证码';
        $scope.nodeBa = 1;
        $scope.hash = '';
        $scope.tamp = '';
        $scope.sterCode = '';
        $scope.referees='';
        $scope.cation = '';
        $scope.pwDStEr = '';
        $scope.NewPwDStEr = '';
        $scope.Send_out = function() {
            if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test($scope.sterCode)) {
                $PlPup.$model('请输入您正确的手机号码');
                return
            }
            $scope.disabledS = true;
            $scope.TimeS = 60;
            $scope.Obtain = 60 + 'S';
            $scope.nodeBa = 2;
            $scope.timerI = $interval(function() {
                $scope.TimeS--;
                $scope.Obtain = $scope.TimeS + 'S';
                if ($scope.TimeS === 0) {
                    $scope.nodeBa = 1;
                    $scope.Obtain = '获取验证码';
                    $interval.cancel($scope.timerI);
                    $scope.disabledS = false;
                    $scope.TimeS = 60;
                    return
                }
            },
            1000);
            $http.post(url + '/user/sendSMS', {
                phoneNumber: $scope.sterCode,
                smstype: verification
            }).success(function(data) {
                if(data.code=="-1"){
                    $PlPup.$model(data.data);
                    $scope.nodeBa = 1;
                    $scope.Obtain = '获取验证码';
                    $interval.cancel($scope.timerI);
                    $scope.disabledS = false;
                    $scope.TimeS = 60;
                    return;
                }
                $scope.hash = data.hash;
                $scope.tamp = data.tamp
            })
        };


        $scope.regiSter = function() {
            if (!/^1[1|2|3|4|5|6|7|8|9][0-9]\d{8}$/.test($scope.sterCode)) {
                $PlPup.$model('请输入您正确的手机号码');
                return
            }
            if ($scope.cation.length !== 4) {
                $PlPup.$model('请输入您正确的验证码');
                return
            }
            if ($scope.hash.length === 0) {
                $PlPup.$model('请先发送短信');
                return
            }
            var reg = /^([0-9]|[a-zA-Z]){6,16}$/;
            var flag = reg.test($scope.pwDStEr);
            if (flag==false) {
                $PlPup.$model('请设置6-16位数字字母组合密码');
                return
            }
            if($scope.referees == ""){
                $scope.referees = "888888";
            }
            if(urls=="/user/register"){
                var regData = {
                    phone: $scope.sterCode,
                    loginpwd: pwdencode($scope.pwDStEr),
                    // pwds: pwdencode($scope.NewPwDStEr),
                    tamp: $scope.tamp,
                    hash: $scope.hash,
                    msgNum: $scope.cation,
                    token: $scope.token,
                    referee:$scope.referees
                };
            }else{
                var regData = {
                    phone: $scope.sterCode,
                    loginpwd: pwdencode($scope.pwDStEr),
                    // pwds: pwdencode($scope.pwDStEr),
                    tamp: $scope.tamp,
                    hash: $scope.hash,
                    msgNum: $scope.cation,
                    token: $scope.token
                };
            }

            $http.post(url + urls, regData).success(function(data) {
                if (data.code === '00') {
                    if(urls=="/user/register"){
                        $http.get(url + "/user/getToken").success(function(data) {
                            $scope.token = data.data
                        }).then(function(){
                            $http.post(url + '/user/login', {
                                phone: $scope.sterCode,
                                loginpwd: pwdencode($scope.pwDStEr),
                                token: $scope.token
                            }).success(function(data) {
                                if (data.code === '00') {
                                    var confirmPopup = $ionicPopup.alert({
                                        title: '提示',
                                        template: '恭喜您注册成功！',
                                        okText: '确定'
                                    });
                                    confirmPopup.then(function (res) {
                                        $state.go("tabs.homepage");
                                    });

                                    return
                                }})

                        })}else{
                        var confirmPopup = $ionicPopup.alert({
                            title: '提示',
                            template: '恭喜您重置密码成功',
                            okText: '确定'
                        });
                        confirmPopup.then(function (res) {
                            var newuser = window.sessionStorage.setItem("newuser",true);
                            $state.go("tabs.homepage");
                        });
                    }
                    return
                }
                if (data.code !== '00') {
                    $scope.token = "";
                    $http.get(url + "/user/getToken").success(function(data) {
                        $scope.token = data.data
                    });
                    $PlPup.$model(data.data);
                    return
                }
            })
        }
    };
    return $sames_up
});
ymb.factory('$sames1',
    function() {
        var $sames_up = {};
        $sames_up.$$same_Up = function($scope, $http, $interval, $go, $PlPup, urls, verification,$ionicPopup,$state) {
            $scope.token = "";
            $http.get(url + "/user/getToken").success(function(data) {
                $scope.token = data.data
            });
            $scope.disabledS = false;
            $scope.Obtain = '获取验证码';
            $scope.nodeBa = 1;
            $scope.hash = '';
            $scope.tamp = '';
            $scope.sterCode = '';
            $scope.referees='';
            $scope.cation = '';
            $scope.pwDStEr = '';
            $scope.NewPwDStEr = '';
            $http.post(url + '/user/selecttotalmoney', {}).success(function(data) {
                $scope.data = data;
            })

            $scope.Send_out = function() {
                $scope.disabledS = true;
                $scope.TimeS = 60;
                $scope.Obtain = 60 + 'S';
                $scope.nodeBa = 2;
                $scope.timerI = $interval(function() {
                        $scope.TimeS--;
                        $scope.Obtain = $scope.TimeS + 'S';
                        if ($scope.TimeS === 0) {
                            $scope.nodeBa = 1;
                            $scope.Obtain = '获取验证码';
                            $interval.cancel($scope.timerI);
                            $scope.disabledS = false;
                            $scope.TimeS = 60;
                            return
                        }
                    },
                    1000);
                $http.post(url + '/user/sendSMS', {
                    smstype: 'reg'
                }).success(function(data) {
                    if(data.code=="-1"){
                        $PlPup.$model(data.data);
                        $scope.nodeBa = 1;
                        $scope.Obtain = '获取验证码';
                        $interval.cancel($scope.timerI);
                        $scope.disabledS = false;
                        $scope.TimeS = 60;
                        return;
                    }
                    $scope.hash = data.hash;
                    $scope.tamp = data.tamp
                })
            };

            //处理设置交易密码
            $scope.settradepwd_up = function(){

                if ($scope.msgNum.length !== 4) {
                    $PlPup.$model('请输入您正确的验证码');
                    return
                }
                if ($scope.hash.length === 0) {
                    $PlPup.$model('请先发送短信');
                    return
                }
                var reg = /^[0-9]{6}$/;
                var flag = reg.test($scope.paypwd);
                if (flag==false) {
                    $PlPup.$model('请设置6位纯数字密码');
                    return
                }
                $http.post(url + '/user/setPaypwd', {
                    paypwd:$scope.paypwd,
                    tamp:$scope.tamp,
                    hash:$scope.hash,
                    msgNum:$scope.msgNum

                }).success(function(data) {
                    if(data.code == "00"){
                        $ionicPopup.alert({
                            title: '提示',
                            template: '恭喜您设置交易密码成功',
                            okText: '确定'
                        }).then(function(){
                                window.sessionStorage.setItem("paypwd",$scope.paypwd);
                                window.history.go(-1);
                            });
                    }
                    return;
                });
            }

        };
        return $sames_up
    });

//设置交易密码
ymb.controller('settrade', ['$scope', '$state', '$ionicViewSwitcher', 'WeChat', 'WecHat', '$http', '$PlPup', '$eye','$ionicPopup','$interval','$sames1','$go',
    function($scope, $state, $ionicViewSwitcher, WeChat, WecHat, $http, $PlPup, $eye,$ionicPopup,$interval,$sames1,$go) {
        WeChat.WxData();
        WecHat.inData('设置交易密码');
        $scope.token = "";
        $eye.$my_eye($scope);
        $sames1.$$same_Up($scope, $http, $interval, $go, $PlPup, '/man/settradepwd', "settradepwd",$ionicPopup);
    }]);

ymb.controller('register', ['$scope', '$http', 'WeChat', 'WecHat','$state', '$sames', '$interval', '$PlPup', '$go', '$eye','$ionicPopup','$ionicModal','$ionicLoading',
    function($scope, $http, WeChat, WecHat,$state, $sames, $interval, $PlPup, $go, $eye,$ionicPopup,$ionicModal,$ionicLoading) {
    WeChat.WxData();
    WecHat.inData('注册');
    $eye.$my_eye($scope);
        $sames.$$same_Up($scope, $http, $interval, $go, $PlPup, '/user/register', "reg",$ionicPopup,$ionicModal,$state,$ionicLoading);
    $scope.returnUpperS = function() {
        $state.go("sign");
    };

    $scope.empty=function(){
        $scope.sterCode="";
        $scope.cation="";
        $scope.pwDStEr="";
        $scope.NewPwDStEr="";
        $scope.referees="";
    }
}]);
ymb.controller('registerxy', ['$scope', 'WeChat', 'WecHat',
function($scope, WeChat, WecHat) {
    WeChat.WxData();
    WecHat.inData('注册协议')
}]);
ymb.controller('forget', ['$scope', '$http', 'WeChat', 'WecHat', '$sames', '$interval', '$PlPup', '$go', '$eye','$ionicPopup','$ionicModal','$state','$ionicLoading',
    function($scope, $http, WeChat, WecHat, $sames, $interval, $PlPup, $go, $eye,$ionicPopup,$ionicModal,$state ,$ionicLoading){
    WeChat.WxData();
    WecHat.inData('忘记密码');
    $eye.$my_eye($scope);
        $sames.$$same_Up($scope, $http, $interval, $go, $PlPup, '/user/findpwd', "resetpwd",$ionicPopup,$ionicModal,$state,$ionicLoading)
}]);
ymb.controller('real', ['$scope', 'WeChat', 'WecHat','$ionicLoading','$state', '$ionicHistory', '$ionicViewSwitcher', '$http', '$PlPup','$ionicPopup',
function($scope, WeChat, WecHat,$ionicLoading,$state, $ionicHistory, $ionicViewSwitcher, $http, $PlPup,$ionicPopup) {
    WeChat.WxData();
    WecHat.inData('实名认证');
    $scope.token = "";
    $http.get(url + "/user/getToken").success(function(data) {
        $scope.token = data.data
    });
    $scope.ok_real = function() {
        var realCode = {
            username: $scope.namesPage,
            idcard: $scope.idcardMin,
            token: $scope.token
        };
        $ionicLoading.show({
            content: 'Loading',
            animation: 'fade-in',
            showBackdrop: true,
            maxWidth: 200,
            showDelay: 0
        });
        $http.post(url + '/user/autonym', realCode).success(function(data) {
            $ionicLoading.hide();
            if (data.code === '33') {
                var confirmPopup = $ionicPopup.alert({
                    title: '提示',
                    template: '恭喜您实名成功',
                    okText: '确定'
                });
               confirmPopup.then(function (res) {
                    $ionicViewSwitcher.nextDirection("back");
                    history.back(-1);
                });

            }
            if (data.code !== '33') {
                $scope.token = "";
                $http.get(url + "/user/getToken").success(function(data) {
                    $scope.token = data.data
                });
                $PlPup.$model(data.data);
                history.back(-1);
            }
        })


    }
}]);
